-- UICommonAlert
-- Created by dengc Oct/30/2016
-- 石柱警戒

UICommonAlert = class("UICommonAlert", function()
    return cc.Layer:create();
end);

function UICommonAlert.create(iconPath)
    return UICommonAlert.new(iconPath);
end

-- 构造函数
function UICommonAlert:ctor(iconPath)
    self:setName("UICommonAlert");
    local node = cc.CSLoader:createNode("layout/stone/StoneAlert.csb");
    self:addChild(node);
    self.node = node;

    self:setLocalZOrder(UIMgr.TOP_MENU_ZORDER + 2);

    -- 记录石柱类型
    self.iconPath = iconPath;

    -- 初始化窗口
    self:initForm();

    -- 适配
    self:resize();
end

-- 初始化窗口
function UICommonAlert:initForm()
    local bg1 = findChildByName(self.node, "CT/bg1");
    local bg2 = findChildByName(self.node, "CT/bg2");
    local bg3 = findChildByName(self.node, "CT/bg3");
    local bg4 = findChildByName(self.node, "CT/bg4");

    local iconPath = self.iconPath;

    bg1:loadTexture(iconPath);
    bg2:loadTexture(iconPath);
    bg3:loadTexture(iconPath);
    bg4:loadTexture(iconPath);

    bg1:setOpacity(0);
    bg2:setOpacity(0);
    bg3:setOpacity(0);
    bg4:setOpacity(0);

    local duration = 1;

    bg1:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeIn:create(duration), cc.FadeOut:create(duration))));
    bg2:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeIn:create(duration), cc.FadeOut:create(duration))));
    bg3:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeIn:create(duration), cc.FadeOut:create(duration))));
    bg4:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeIn:create(duration), cc.FadeOut:create(duration))));
end

-- 适配
function UICommonAlert:resize()
    local node = self.node;
    local w = AlignM.frameSize.width;
    local h = AlignM.frameSize.height;
    node:setContentSize(w, h);

    local  ct = findChildByName(node, "CT");
    ct:setPosition(w/2, h/2);
    ct:setScaleX(w/DESIGN_WIDTH);
    ct:setScaleY(h/DESIGN_HEIGHT);
end



